package com.loser.module.sql.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TypeConverter {

    public static Object convert(String input) {
        // 匹配 Integer
        Pattern intPattern = Pattern.compile("^-?\\d+$");
        Matcher intMatcher = intPattern.matcher(input);
        if (intMatcher.matches()) {
            return Integer.parseInt(input);
        }

        // 匹配 Double
        Pattern doublePattern = Pattern.compile("^-?\\d*\\.\\d+$");
        Matcher doubleMatcher = doublePattern.matcher(input);
        if (doubleMatcher.matches()) {
            return Double.parseDouble(input);
        }

        // 匹配 Boolean
        Pattern booleanPattern = Pattern.compile("^(true|false)$", Pattern.CASE_INSENSITIVE);
        Matcher booleanMatcher = booleanPattern.matcher(input);
        if (booleanMatcher.matches()) {
            return Boolean.parseBoolean(input.toLowerCase());
        }

        // 其他情况当作 String 处理
        return input;
    }

}
